import { reqGetTradeInfoData } from "@/api/index"
const state = {
  tradeInfo: {},
}
const actions = {
  // 获取订单交易信息
  async getTradeInfoData({ commit }) {
    const result = await reqGetTradeInfoData()
    // console.log(result)
    if (result.code === 200) {
      // console.log("获取订单信息成功", result.data)
      commit("SAVE_TRADE_INFO_DATA", result.data)
    } else {
      console.log("获取订单信息失败", result.message)
    }
  },
}
const mutations = {
  // 保存订单交易数据
  SAVE_TRADE_INFO_DATA(state, payload) {
    state.tradeInfo = payload
  },
}
const getters = {
  // 1. 订单编号
  tradeNo(state) {
    // console.log(state.tradeInfo.tradeNo)
    return state.tradeInfo.tradeNo
  },
  // 2. 商品数量
  totalNum(state) {
    return state.tradeInfo.totalNum
  },
  // 3. 商品详细列表
  detailArrayList(state) {
    return state.tradeInfo.detailArrayList
  },
  // 4. 总金额
  totalAmount(state) {
    return state.tradeInfo.totalAmount
  },
}

export default {
  namespaced: true,
  state,
  actions,
  mutations,
  getters,
}
